package com.lj.universalframework.ui.activity

import android.view.View
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.lj.universalframework.R
import com.lj.universalframework.databinding.ActivityMainBinding
import com.lj.universalframework.dialog.BottomDialogFragment01
import com.lj.universalframework.ui.BaseActivity
import com.lj.universalframework.ui.viewModel.MainViewModel
import com.lj.universalframework.utils.clickWithTrigger
import com.lj.universalframework.utils.openActivity
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {

    override fun initData() {

        tv_cs.clickWithTrigger {
            mViewModel.loadDSL()
        }

        tv_cs_02.clickWithTrigger {
            mViewModel.logIn()
        }

        tv_cs_03.clickWithTrigger {
            mViewModel.cs03()
            openActivity<MainActivity2>()
        }
        tv_fragment_botton_dialog.clickWithTrigger {
            BottomDialogFragment01.getInstance().show(supportFragmentManager, "dialog")
        }

        tv_botton_dialog.clickWithTrigger {
            val bottomSheetDialog = BottomSheetDialog(this)
            val view = View.inflate(this, R.layout.dottom_frggment_dialog, null)
            view.apply {
                findViewById<TextView>(R.id.tv_shut_down).apply {
                    setOnClickListener {
                        bottomSheetDialog.dismiss()
                    }
                }
            }
            bottomSheetDialog.setContentView(view)
            bottomSheetDialog.show()
            //设置透明背景,必须在最后面
            bottomSheetDialog.window!!.findViewById<View>(R.id.design_bottom_sheet)
                .setBackgroundResource(android.R.color.transparent)
        }

        tv_file_download.clickWithTrigger {
            openActivity<MaterialUIActivity>()
        }
    }
}
